/* 侯捷 c++第二课 */
#include <iostream>
using namespace std;

template<class T>
class shared_ptr {
public:
    shared_ptr(T* p) : px(p) {}
    T& operator*() const { return *px; }
    T* operator->() const { return px; }
private:
    T* px;
};

class Foo {
public:
    Foo() { 
        cout << "Foo::Foo() " << this << endl;
    }
    Foo(Foo &f) {
        cout << "Foo::Foo(Foo &f) " << this << endl;
        f.method();
    }
    void method(void) { cout << "Foo::method " << this << endl; }
};

int main(int argc, char **argv)
{
    cout << "======= start =========" << endl;

    shared_ptr<Foo> sp(new Foo);
    Foo f(*sp);
    sp->method();

    cout << "======== end ==========" << endl;

    return 0;
}
